#ifndef XDIVA_NODEMANAGER_H
#define XDIVA_NODEMANAGER_H

#include "AbstractManager.h"
#include <vector>
#include <map>

class AbstractMappingWindow;
class NodeItem;
class LineItem;
class TypeEntryItem;
class TerminalNodeShape;
class xMappingTree;
class TypeVariableEntry;
class NodePort;
class NodeInPort;
class NodeOutPort;
class WOP_Entry;
class xMappingNode;
class AbstractShapeItem;
class TypeVariablePanel;
class QPointF;
class TypeEntryFrameItem;
class DiagramScene;

class TypeManager : public AbstractManager {
public:
	
	TypeManager(AbstractMappingWindow* );
	virtual ~TypeManager();

	virtual AbstractPanel * createInputPanel();
	virtual AbstractPanel * createOutputPanel();

	TypeEntryItem * createEntryItem( const std::string &, const std::string &, xMappingNode *,WOP_Entry *, TypeEntryFrameItem * = nullptr );
	void createEntry( WOP_Entry * , bool );
	void deleteEntry();
	void createArrEntry( WOP_Entry* );
	void createPtvEntry( WOP_Entry* );
	void createRefEntry( WOP_Entry* );
	void createObjEntry( WOP_Entry* );
	TypeVariableEntry* getEntry();
	void initVariableEntry( WOP_Entry* );
	void unfoldEntry( WOP_Entry* );
	NodeItem* getRootNode();
	void saveMapping(QString ,WOP_Entry* );

	void setSaveFileName( const QString & );
	const QString & getSaveFileName() const;
	void addMDSString( WOP_Entry * );		//add mds string in diva
	void deleteEmptyPort();
	
	NodeItem* getRoot();
	bool checkRootNumberValidate();
	void reset();
	TypeVariablePanel* getVariablePanel();
	std::vector<TypeEntryItem*> createUnfoldEntries(WOP_Entry *entry);
	void createEntryFrameItem(WOP_Entry* entry, std::vector<xMappingNode*> &entryList, DiagramScene* scene, AbstractPanel* panel);
//	NodeItem * createNode( WOP_Entry * en );

	void saveVMtoDESFiles( const QString & fileName, const QString & type, const QString & description );

protected:
	QString _saveFileName;	// mapping tree 存成 mds檔案的檔名
	TypeVariableEntry* _mpnEntry;
	NodeItem* _root;			// 最後連接到TerminalNode的mapping node
	TypeVariablePanel* iPanel_;
	TypeEntryItem* findEntryItemByName( const std::string & );
	
};

#endif
